﻿/// <reference path="jquery-2.1.0.intellisense.js" />
Parse.initialize("bWl9D4Qrxa8ioRsXrZNmMDp0TEOdE6FfXWQslZ2b", "8VV4L5PZyM5hGdwX1y9wATAolbVyNvwz8tuVCQvu");

var currentUser = Parse.User.current();
if (currentUser) {
    var user = eval('(' + JSON.stringify(currentUser) + ')');
    document.getElementById('login').innerHTML = "Hello " + user.heroname + '<button class="btn btn-danger" id="logout" onclick="logout()">Logout</button>'

    
} else {
    document.getElementById('login').innerHTML = '<form class="form-inline pull-right" onsubmit="return false" role="form"><div class="form-group"><label class="sr-only" for="exampleInputEmail2">Username</label><input type="text" class="form-control" id="username" placeholder="Enter username"></div><div class="form-group"><label class="sr-only" for="exampleInputPassword2">Password</label><input type="password" class="form-control" id="password" placeholder="Password"></div><div class="checkbox"><label><input type="checkbox"> Remember me</label></div><button onclick="login()" class="btn btn-primary">Sign in</button><button class="btn btn-info" onclick="redirect()">Register</button></form>';
}
function login() {
    var username = document.getElementById('username').value;
    var password = document.getElementById('password').value;
    Parse.User.logIn(username, password, {
        success: function (user) {
            location.reload();
        },
        error: function (user, error) {
            console.log(JSON.stringify(error))
        }
    });
}
function logout() {
    Parse.User.logOut();
    location.reload();
}
function redirect() {
    window.location = "register.html"
}